package com.kedacom.demo.app;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.jmx.SigarRegistry;

public class MonitorRunnable implements Runnable {

    private static final Logger logger = Logger.getLogger(MonitorRunnable.class.getName());
    private long interval = 1000;
    private final Sigar sigar = new Sigar();
    private final SigarRegistry sr = new SigarRegistry ();
    static final String DOMAIN = "MyMBeanDynamic";  

    MonitorRunnable() {
    }

    MonitorRunnable(long interval) {
        this.interval = interval;
    }

    public long getInterval() {
        return interval;
    }

    public Sigar getSigarl() {
        return sigar;
    }

    public void setInterval(long interval) {
        this.interval = interval;
    }

    @Override
    public void run() {
        try {  
//            //创建一个MBean服务对象，DOMAIN类似于java里面的公共package部分  
//            MBeanServer server = MBeanServerFactory.createMBeanServer(DOMAIN);  
//            //创建DynamicMBean对象  
//            PersonDynamic personDynamic = new PersonDynamic();  
//            //创建一个web服务器，表示我们MBean服务通过web形式来提供给用户管理  
//            HtmlAdaptorServer htmlServer = new HtmlAdaptorServer();  
//            htmlServer.setPort(9999);//设置web端口为9999  
//            //ObjctName对象类似于完整的package  
//            ObjectName personObjName = new ObjectName(DOMAIN+":name=PersonDynamic");  
//            ObjectName htmlObjName = new ObjectName(DOMAIN+":name=HtmlAdaptor");  
//            //将需要被管理的MBean注册到服务里面去  
//            server.registerMBean(personDynamic, personObjName);  
//            //将web服务器注册到服务里面去  
//            server.registerMBean(htmlServer, htmlObjName);  
//            //启动web服务器  
//            htmlServer.start();  
//            System.out.println("正在启动HtmlAdaptor..");  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        
        while (true) {
            try {
                logger.info("MonitorRunnable Is Running...");
                Thread.sleep(interval);
            }
            catch (InterruptedException e) {
                logger.log(Level.SEVERE, e.getMessage());
            }
        }

    }
}
